/*
 * <<
 *  Davinci
 *  ==
 *  Copyright (C) 2016 - 2019 EDP
 *  ==
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *        http://www.apache.org/licenses/LICENSE-2.0
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *  >>
 *
 */

package com.cwf.metadatamanage.model.dtos;

import com.alibaba.druid.util.StringUtils;
import com.cwf.metadatamanage.consts.Constants;
import com.cwf.metadatamanage.exception.ServerException;
import lombok.Data;

@Data
public class ColumnDto {

    private String id;

    /**
     * 字段名
     */
    private String columnName;

    /**
     * 字段描述
     */
    private String columnRemarks;

    /**
     * 字段类型
     */
    private String columnType;

    /**
     * 字段描述
     */
    private String columnDescription;

    /**
     * 描述
     */
    private String description;

    public ColumnDto(String name, String type) {
        if (StringUtils.isEmpty(name)) {
            throw new ServerException("Empty column name");
        }
        if (StringUtils.isEmpty(type)) {
            throw new ServerException("Empty column type, column: " + name);
        }
        this.columnName = name;
        this.columnType = type.toUpperCase();
    }

    public ColumnDto(String name, String type, String remarks,String description) {
        if (StringUtils.isEmpty(name)) {
            throw new ServerException("Empty column name");
        }
        if (StringUtils.isEmpty(type)) {
            throw new ServerException("Empty column type, column: " + name);
        }
        this.columnName = name;
        this.columnType = type.toUpperCase();
        this.columnRemarks = remarks;
        this.columnDescription = description;
    }

    public void setType(String type) {
        this.columnType = type == null ? Constants.EMPTY : type;
    }
}
